package dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.logging.Level;
import java.util.logging.Logger;

import entities.ExecSeq;
import entities.Process;
import factory.DBConnectionFactory;

public class MYSQLExecSeqDAO extends ExecSeqDAO{

	@Override
	public LinkedList<ArrayList<ExecSeq>> getExecSeq() {
		// TODO Auto-generated method stub
		 DBConnectionFactory myFactory = DBConnectionFactory.getInstance(DAOFactory.MYSQL);
		    Connection conn = myFactory.getConnection();
		    PreparedStatement pstmt3;
		     ArrayList<ExecSeq> ex = new ArrayList<ExecSeq>();
	        LinkedList<ArrayList<ExecSeq>> exs=new LinkedList<ArrayList<ExecSeq>>();
	        ExecSeq e; String str;
	        try {
				pstmt3 = conn.prepareStatement("SELECT * FROM [ExecSeq$]");
		        ResultSet rs = pstmt3.executeQuery();
		        while(rs.next()){
		        	e = new ExecSeq();
		        	
		        	
		        	e.setProcessID(rs.getInt(1));
		        	e.setSequence(rs.getInt(2));
		        	str=rs.getString(3);
		        	if(!str.equals("END")){
		        		
		        		e.setExecute(str);
		        		e.setInstance(rs.getInt(4));
		        		e.setParameter(rs.getString(5));
		        		e.setDuration(rs.getInt(6)); 
		        	}
		        	ex.add(e);
		        	if(str.equals("END")){
		        		
		        		exs.add(ex);
		        		ex = new ArrayList<ExecSeq>();
		        	}
		        	
		        }
			} catch (SQLException x) {
				// TODO Auto-generated catch block
				 Logger.getLogger(MYSQLExecSeqDAO.class.getName()).log(Level.SEVERE, null, x);
			} 	
		return exs;
	}

	@Override
	public String[] getExecSeqCol() {
		// TODO Auto-generated method stub
		String[] execseq = {"ProcessID", "Sequence", "Execute", "Instance", "Parameter", "Duration"};
		return execseq;
	}

}
